{  Statement: http://acmp.ru/?main=task&id_task=150
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,j,n,k,t,ans:longint;
    a:array[0..110,0..110] of boolean;
    w:array[0..110] of boolean;

procedure dfs(v:longint);

var
    i:longint;
    
begin
w[v] := true;
for i:=1 to n do
    if a[v][i] and (not w[i]) then begin
        inc(ans);
        dfs(i);
    end;
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
fillchar(a,sizeof(a),0);
fillchar(w,sizeof(w),0);
read(n,k);
for i:=1 to n do
    for j:=1 to n do begin
        read(t);
        a[i][j] := t = 1;
    end;
ans := 0;
dfs(k);
write(ans);
end.

